cmake_minimum_required(VERSION 3.10)

if (NOT EXISTS ${EXECUTABLE_OUTPUT_PATH})
	file(MAKE_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
	if (NOT EXISTS ${EXECUTABLE_OUTPUT_PATH}/simpleble.lib)
		file(COPY win/lib/simpleble.lib DESTINATION ${EXECUTABLE_OUTPUT_PATH})
	endif()
	if (NOT EXISTS ${EXECUTABLE_OUTPUT_PATH}/simpleble.dll)
		file(COPY win/lib/simpleble.dll DESTINATION ${EXECUTABLE_OUTPUT_PATH})
	endif()
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
	if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64")
		file(COPY mac/x64/lib/libsimpleble.dylib DESTINATION ${EXECUTABLE_OUTPUT_PATH})
	elseif (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64")
		file(COPY mac/arm64/lib/libsimpleble.dylib DESTINATION ${EXECUTABLE_OUTPUT_PATH})
	else()
		message(FATAL_ERROR "Unsupported architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
	endif()
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
	if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "arm")
		file(COPY linux/arm/lib/libsimpleble.a DESTINATION ${EXECUTABLE_OUTPUT_PATH})
	elseif (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64")
		file(COPY linux/arm64/lib/libsimpleble.a DESTINATION ${EXECUTABLE_OUTPUT_PATH})
	elseif (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64")
		file(COPY linux/x64/lib/libsimpleble.a DESTINATION ${EXECUTABLE_OUTPUT_PATH})
	else()
		message(FATAL_ERROR "Unsupported architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
	endif()
else()
	message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
endif()
